package com.daqian.cloud.ali.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author: daqian
 * @date: 2019/6/13 16:51
 */
@Component
@Order(-1)
public class AuthFilter implements GlobalFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        String token = exchange.getRequest().getHeaders().getFirst("token");
//        if (!"token".equals(token)) {
//            throw UnauthorizedException.msg("非法请求");
//        }
        System.out.println("-------------Here is AuthFilter.");
        System.out.println("auth filter token is: " + token);
        return chain.filter(exchange);
    }
}
